Skip to content

refactor(runtime): 第一阶段剥离 context 模块#102

Merged
minorcell merged 3 commits into
1024XEngineer:mainfrom
wynxing:codex/issue-101-context-builder
Apr 1, 2026
Merged

refactor(runtime): 第一阶段剥离 context 模块#102
minorcell merged 3 commits into
1024XEngineer:mainfrom
wynxing:codex/issue-101-context-builder

Conversation

@wynxing

@wynxing wynxing commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator

概要

  • internal/runtime 中的 system prompt 构建与消息裁剪逻辑抽离到独立的 internal/context 模块
  • 让 runtime 改为依赖注入的 context.Builder,保持 provider、tools 和 TUI 的外部行为不变
  • 增加 context 模块独立测试,并将 runtime 测试调整为验证委托关系而不是私有裁剪实现

背景

Issue #101 的目标是先完成第一阶段的“行为等价迁移”,把上下文构建职责从 ReAct 主循环中剥离出来,为后续规则文件注入、compact 和 memory 等能力预留清晰扩展点。

主要改动

  • 新增 internal/context,提供 BuilderBuildInputBuildResult、默认 prompt 构建和按 span 裁剪消息的实现
  • internal/app 中注入默认 context builder,并由 runtime 在每轮请求前统一构建上下文
  • 移除 runtime 内部的 prompt / trim 私有实现,改为在调用 Provider.Chat 前使用 builder 输出
  • 更新 README 与 runtime 事件流文档,补充 internal/context 的职责说明

验证

  • go test ./...

说明

@wynxing wynxing changed the title [codex] refactor(runtime): extract context builder from runtime [codex] refactor(runtime): 第一阶段剥离 context 模块 Apr 1, 2026
@wynxing wynxing marked this pull request as ready for review April 1, 2026 07:41
@codecov

codecov Bot commented Apr 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/runtime/runtime.go 80.00% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@minorcell minorcell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yumiue 看看

Comment thread internal/context/prompt.go
Comment thread internal/context/trim.go Outdated
Comment thread internal/runtime/runtime.go Outdated
Comment thread internal/runtime/runtime.go
Comment thread internal/runtime/runtime.go
@minorcell minorcell changed the title [codex] refactor(runtime): 第一阶段剥离 context 模块 refactor(runtime): 第一阶段剥离 context 模块 Apr 1, 2026
@minorcell minorcell merged commit 4782eb0 into 1024XEngineer:main Apr 1, 2026
2 checks passed
@wynxing wynxing deleted the codex/issue-101-context-builder branch April 15, 2026 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants